<?php


namespace App\Utils;


trait ResponseTrait
{
    /**
     * 成功返回
     * @param array $data
     * @return array
     */
    protected function ok(array $data = null): array
    {
        $errorCode = ErrorCode::OK;
        return ['code' => $errorCode[1], 'message' => $errorCode[0], 'data' => $data];
    }

    /**
     * 出错返回
     * @param $message
     * @param int $code
     * @param array|null $data
     * @return array
     */
    protected function error(string $message, int $code = 1, array $data = null): array
    {
        return ['code' => $code, 'message' => $message, 'data' => $data];
    }

    /**
     * 参数错误
     * @return array
     */
    protected function invalidParameter(): array
    {
        return $this->error(...ErrorCode::INVALID_PARAMETER);
    }
}